<template>
  <div>
    <c-list id-key="id" ref="list" show-index :disabled="disabled" :show-checkbox="showCheckbox" :query-params="queryParams"
      page custom-get-data :data="data" :total="total" @get-data="getData">
      <template slot="toolbar-left">
        <slot name="toolbar-left"></slot>
      </template>
      <template #query>
        <el-form-item label="接口名称">
          <el-input v-model.trim="queryParams.name" clearable></el-input>
        </el-form-item>
        <el-form-item label="接口路径">
          <el-input v-model.trim="queryParams.path" clearable></el-input>
        </el-form-item>
      </template>
      <template #column>
        <el-table-column prop="name" width="200" label="接口名称" show-overflow-tooltip />
        <el-table-column prop="path" min-width="200" label="接口路径" show-overflow-tooltip />
        <!-- slot[column] -->
        <slot name="column"></slot>
        <!--/ slot[column]-->
      </template>
    </c-list>
  </div>
</template>
<script>
import list from "@/components/common/list.vue";
import api from "@/api/sys/api";
export default {
  components: {
    list
  },
  props: {
    inDialog: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    showCheckbox: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      data: [],
      total: 0,
      //查询条件字段
      queryParams: {
        name: "",
        path: ""
      }
    };
  },
  computed: {
    commonList() {
      return this.$refs.list;
    }
  },
  methods: {
    async getData(params) {
      this.$refs.list.loading();
      let res = await api.getPageList(params);
      this.$refs.list.loading(false);
      if (res.code != 0) {
        return;
      }
      this.data = res.data.list;
      this.total = res.data.total;
    },
    async deleteById(id) {
      await this.$confirm("确认要删除此接口吗", "提示", {
        type: "warning"
      });
      const res = await api.deleteById(id)
      if (res.code != 0) { return; }
      this.commonList.reload();
    }
  }
};
</script>